#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 100100;
int tree[maxn][27];
int flag[maxn];
char s[30],str1[maxn][15],str2[15];
int tol = 0;
void insert(char *s,int aim)
{
	int rt = 0;
	int len = strlen(s);
	for(int i = 0;i<len;i++)
	{
		int id = s[i]-'a';
		if(!tree[rt][id]) tree[rt][id] = ++tol;
		rt = tree[rt][id];
	}
	flag[rt] = aim;
}
int find(char *s)
{
	int rt = 0;
	int len = strlen(s);
	for(int i = 0;i<len;i++)
	{
		int id = s[i]-'a';
		if(!tree[rt][id]) return -1;
		rt = tree[rt][id];
	}
	return flag[rt];
}		
int main()
{
	int aim = 0;
	while(gets(s)&&strlen(s))
	{
		sscanf(s," %s %s",str1[aim],str2);
		insert(str2,aim++);
	}
	while(scanf(" %s",str2)!=EOF)
	{
		int ans = find(str2);
		if(ans == -1) printf("eh\n");
		else puts(str1[ans]);
	}
}
